<?php

/*
 * 城市数据类
 */
class Application_Model_DbTable_city extends Application_Model_DbTable_DomainObject{
    
        protected $_name = 'uuch_city_new';	
        
	public function getMapper(){
		return array('id','country','name','parentId','type','ename','serviceFee','sortid','percent','state','default','continent','areaCode','hot','sortcode','word');
	}
        
        /*
         * 根据国家获取对应城市列表
         */
        public function  getbycountry($continent){
            $db = $this->getAdapter();
            $filter = $db->quoteInto(' continent = ?', $continent);            
            $rows = $this->fetchAll($filter,'id');
            
            $result = array();
            foreach ($rows as $row){
                array_push($result,$this->convertRowToObject($row));                    
            }           
            return $result;
        }
        
         /*
         * 根据上级序号查询
         */
        public function  GetByParentId($ParentID,$returnType){
            $db = $this->getAdapter();
            $filter = $db->quoteInto(' parentId = ?', $ParentID);            
            $rows = $this->fetchAll($filter,'id');
            $result = array();
            foreach ($rows as $row){
                if($returnType=='array')
                    array_push($result,$this->convertRowToObject($row));
                else
                    array_push($result,$this->convertRowToArray($row));
            }           
            return $result;
        }
        
        /*
         * 获取热门城市信息
         */
        public  function  GetByhot($parentId)
        {
            $db = $this->getAdapter();
            $filter = $db->quoteInto(' hot = ?', 1);            
            $filter .= $db->quoteInto(' and parentId = ?', $parentId);            
            $rows = $this->fetchAll($filter,'id');
            $result = array();
            foreach ($rows as $row){
                    array_push($result,$this->convertRowToObject($row));
            }           
            return $result;
        }
        
        /*
         * 根据第一个字母查找城市
         */
        public  function  GetBySortCode($sortcode,$parentId)
        {
            $db = $this->getAdapter();
            $filter = $db->quoteInto(' sortcode = ?', $sortcode);        
            $filter .= $db->quoteInto(' and parentId = ?', $parentId);
            $filter .= $db->quoteInto(' or ename like ?', $sortcode.'%');
            $rows = $this->fetchAll($filter,'hot desc');
            $result = array();
            foreach ($rows as $row){
                    array_push($result,$this->convertRowToObject($row));
            }           
            return $result;
        }
}
?>
